package com.hottv.meeting.videomeeting.module.file.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hottv.meeting.videomeeting.MeetingActivity;
import com.hottv.meeting.videomeeting.R;
import com.hottv.meeting.videomeeting.common.MeetingConfig;
import com.hottv.meeting.videomeeting.module.file.adapter.FolderDataRecycleAdapter;
import com.hottv.meeting.videomeeting.module.file.model.FileInfo;
import com.hottv.meeting.videomeeting.module.white.DoCallback;

import java.util.List;

import static android.app.Activity.RESULT_OK;

/**
 * Created by yis on 2018/4/17.
 */

public class FolderDataFragment extends Fragment {

    private RecyclerView rvDoc;

    private DoCallback mCallback;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_doc, container, false);
        rvDoc = (RecyclerView)rootView.findViewById(R.id.rv_doc);
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initData();
    }

    private void initData() {
        Bundle bundle = this.getArguments();

        List<FileInfo> data = bundle.getParcelableArrayList("file_data");
        boolean isImage = bundle.getBoolean("is_image");

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        //设置RecyclerView 布局
        rvDoc.setLayoutManager(linearLayoutManager);
        FolderDataRecycleAdapter pptListAdapter = new FolderDataRecycleAdapter(getActivity(), data, isImage, new DoCallback() {
            @Override
            public void onSuccess(String info) {
                Log.i(MeetingConfig.TAG,"----FolderDataRecycle------------");
                Intent data = new Intent();
                Bundle bundleFile = new Bundle();
                bundleFile.putString("file",info);
                data.putExtras(bundleFile);
                getActivity().setResult( RESULT_OK, data);

//                getActivity().startActivityForResult(data,12);
                getActivity().finish();
            }

            @Override
            public void onFailor(String info) {

            }

            @Override
            public void onProcess(String info) {

            }
        });
        rvDoc.setAdapter(pptListAdapter);
    }
}
